<template>
	<view class="content">
		<scroll-view class="scroll-view" scroll-y="true" @scroll="scroll" @scrolltolower="lower" :style="'height:'+scriptHeight+'px'">
			<view class="first">
				<view class="item"><text class="item-text" @click="click_cyjl">成语接龙</text></view>
				<view class="item"><text class="item-text" @click="click_zhsc">中华诗词</text></view>
				
				<view class="item"><text class="item-text" @click="click_poet">诗人大全</text></view>
				<view class="item"><text class="item-text" @click="click_phb">排行榜</text></view>
				<!-- <view class="item"><text class="item-text">猜谜语</text></view> -->
			</view>
			<view class="second" >
				<view class="title"><text>每天一首古诗</text></view>
				<view class="item" @click="recommendToUrl(recommend.id)" v-if="recommend != ''">
					<view class="item-text">{{recommend.content}}</view>
					<view class="item-author">{{recommend.title}}-{{recommend.dynasty}}-{{recommend.author}}</view>
				</view>
			</view>
			<view class="poet">
				<view class="title">热门诗人</view>
				<view class="content">
					<view class="item" v-for="(item,index) in poet" :key="index" @click="clickpoet(item.id)">
						<view class="avatar"><image :src="item.avatar"></image></view>
						<view class="name">{{item.name}}</view>
					</view>
				</view>
			</view>
			<view class="chengyu">
				<view class="title">成语精选</view>
				<view class="content">
					<view class="item" v-for="(item,index) in chengyu" :key="index" @click="clickchengyu(item.id)">{{item.title}}</view>
				</view>
			</view>
			
			<view class="title"><text>诗词精选</text></view>
			
			<view class="third" v-for="(item,index) in list" :key="index" @click="toUrl(item.id)">
				<view class="item">
					<view class="item-text">{{item.content}}</view>
					<view class="item-button">
						<view class="left">{{item.title}}-{{item.dynasty}}-{{item.author}}</view>
						<view class="right">{{item.hit}} 人浏览</view>
					</view>
				</view>
			</view>
			
		</scroll-view>
	</view>
</template>

<script>
	import unils from "../../unils/utils.js"
	export default {
		data() {
			return {
				title: 'Hello',
				'scriptHeight':400,
				'list':[],
				'recommend':"",
				'poet':[],
				'chengyu':[],
			}
		},
		onShareAppMessage(res) {
			// console.log('========share========');
		    if (res.from === 'button') {// 来自页面内分享按钮
			  console.log(res);
		      console.log(res.target)
		    }
			// console.log(this.openid);
			let openid = uni.getStorageSync('openid');
			// console.log(openid);
		    return {
		      title: '一起来学习诗词古语！',
		      path: '/pages/index/index?share_user_id='+openid,
		    }
		  },
		onLoad() {
			let that = this;
			uni.showLoading({title: '加载中',mask:true});
			uni.request({
				url: that.websiteUrl+'/indexpoetry',
				method:'GET',
				header: {
				        'x-requested-with': 'xmlhttprequest' //自定义请求头信息
				    },
				data:{
					// 'openid':that.openid,
				},
				success:(res)=>{
					if(res.data.code != 1){
						uni.showToast({
							title:"网络错误！",
							duration:2000,
							icon:'none',
						})
					} else {
						that.recommend = res.data.data.recommend[0];
						that.list = res.data.data.list;
						that.poet = res.data.data.poet;
						that.chengyu = res.data.data.chengyu;
						// console.log(that.recommend);
					}
					
				},
				complete: (res) => {
					setTimeout(function () {uni.hideLoading();}, 100);
				} 
			})
		},
		onReady() {
			this.scriptHeight = uni.getSystemInfoSync().windowHeight;
		},
		methods: {
			lower:function(){
				// console.log('scrolltolower');
			},
			scroll:function(e){
				// console.log('lower');
			},
			click_cyjl:function(){
				unils.needLoginJump("../fight/fight");
			},
			click_zhsc:function(){
				unils.needLoginJump("../shici/shici",2);
			},
			click_phb:function(){
				unils.needLoginJump("../ranking/ranking");
			},
			toUrl:function(id){
				uni.navigateTo({
					url:"../article_sc/article_sc?id="+id
				})
			},
			click_poet:function(){
				uni.navigateTo({
					url:"../poet/poet"
				})
			},
			recommendToUrl:function(id){
				uni.navigateTo({
					url:"../article_sc/article_sc?id="+id
				})
			},
			clickchengyu:function(id){
				uni.navigateTo({
					url:"../article_cy/article_cy?id="+id
				})
			},
			clickpoet:function(id){
				uni.navigateTo({
					url:"../shici/list?poet_id="+id
				})
			}
		}
	}
</script>

<style lang="scss">
.content{
	.scroll-view{
		height: 450px;
		background-color: $uni-scroll-bg-clolr;
		.first{
			display: flex;
			align-items: center;
			justify-content: space-around;
			.item{
				width:50px;
				height: 100px;
				margin: 30px 10px 10px 10px;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: row;
				border-radius: 8px;
				background-color: $uni-primary-color;
				.item-text{
					font-size:16px;
					font-weight: blod;
					display: flex;
					flex-direction:row;  /* 子元素横向排列 */
					justify-content: center;/*对父元素水平居中 */
					justify-items: center;
					align-items: center; /*  子元素相对父元素垂直居中 */
					width:20px;
					height: 100px;
					color:#FFFFFF;
				}
			}
		}
		.second{
			.title{
				display: flex;
				justify-content: center;
				font-weight: bold;
				font-size: 16px;
				color:$uni-primary-color;
				margin: 10px auto;
			}
			.item{
				color:$uni-text-color;
				font-size: $uni-list-content-font-size;
				margin:0 10px;
				background-color: #ffffff;
				padding:10px;
				border-radius: 3px;
				.item-text{
					
				}
				.item-author{
					font-weight: bold;
					font-size:14px;
					margin-top: 10px;
					display: flex;
					justify-content: flex-end;
					padding-right: 3px;
					color:$uni-text-color;
				}
			}
		}
		.title{
			display: flex;
			justify-content: center;
			font-weight: bold;
			font-size: 16px;
			color:$uni-primary-color;
			margin: 10px auto;
			height: 40px;
			line-height: 40px;
		}
		.third{
			
			.item{
				font-size: $uni-list-content-font-size;
				margin: 15px 10px;
				background-color: #FFFFFF;
				padding:10px 10px;
				border-radius: 3px;
				color:$uni-text-color;
				
				.item-text{
					
				}
				.item-button{
					font-size:12px;
					display: flex;
					// justify-content: flex-end;
					margin-top: 10px;
					.left{
						font-size: 14px;
						font-weight: bold;
						// display: flex;
						// justify-content: flex-start;
						width: 100%;
						color:$uni-text-color;
					}
					.right{
						flex-shrink: 0;
						
						color:$uni-primary-color;
						display: flex;
						justify-content: flex-end;
						padding-right: 3px;
					}
				}
			}
		}
	}
	//诗人
	.poet{
		.title{
			// color: #007AFF;
			height: 40px;
			line-height: 40px;
			margin: 10px 0;
		}
		.content{
			margin: 0 10px;
			display: flex;
			align-items: center;
			justify-content: space-around;
			flex-wrap: wrap;
			background-color: $uni-bg-color;
			border-radius: 5px;
			.item{
				margin: 10px;
				display: flex;
				flex-direction: column;
				.avatar{
					image{
						width:50px;
						height:50px;
						border-radius: 50%;
					}
				}
				.name{
					display: flex;
					justify-content: center;
					font-size:$uni-list-content-font-size;
					color: $uni-text-color;
				}
			}
		}
	}
	//成语
	.chengyu{
		.title{
			height: 40px;
			line-height: 40px;
			margin: 10px 0;
		}
		.content{
			display: flex;
			justify-content: space-around;
			flex-wrap: wrap;
			margin: 0 10px;
			background-color: $uni-bg-color;
			padding: 10px 0;
			// flex-direction: column;
			.item{
				background-color: $uni-primary-color;
				color:$uni-bg-color;
				border-radius: 5px;
				// width:70px;
				padding: 5px;
				margin: 8px 0px;
				font-size: 14px;
				// margin: 10px;
			}
		}
	}
}
</style>
